#pragma once
#include "afxwin.h"
#include "Utility.h"

// CSetDlg dialog

class CSetDlg : public CDialog
{
	DECLARE_DYNAMIC(CSetDlg)

public:
	CSetDlg(CWnd* pParent = NULL);   // standard constructor
	virtual ~CSetDlg();

	void SetDeviceName(const CString& strName) {m_deviceDef.DeviceName = strName;}
	CString GetDeviceName() const {return m_deviceDef.DeviceName;}

	void SetDeviceLDN(const CString& strLDN) {m_deviceDef.DeviceLDN = strLDN;}
	CString GetDeviceLDN() const {return m_deviceDef.DeviceLDN;}

	void SetDeviceClass(const CString& strClass) { m_deviceDef.DeviceClass = strClass;}
	CString GetDeviceClass() const {return m_deviceDef.DeviceClass;}

	void SetSysFileInfo(const CString& strFile) { m_strSysFile = strFile;}
	
	int GetBoudRate() const {return m_deviceDef.PortSetting.nBoudRate;}
	int GetpParigy() const {return m_deviceDef.PortSetting.nParity;}

	const DeviceDefinition& GetDeviceDefinition() {return m_deviceDef;}
	enum EDataSource
	{
		ESYSFILE,
		EREG,
		EOTHERS
	};
	void SetDataSouce(CSetDlg::EDataSource eSource) {m_eDataSouce = eSource;}

// Dialog Data
	enum { IDD = IDD_DLG_SETTING };

protected:
	virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
	virtual BOOL OnInitDialog();
	afx_msg void OnBnClickedOk();

	DECLARE_MESSAGE_MAP()

private:
	int LoadDeviceInfoFromSysFile();
	int ConfigSerialByReg();
	int GetSerialCount();
	BOOL ConfigSerialByFile(CString strFileName);

private:
	CString m_strSysFile;
	EDataSource m_eDataSouce;

	// Control variables
	CComboBox m_cmbPort;
	CComboBox m_cmbParity;
	CComboBox m_cmbBR;
	CComboBox m_cmbSB;
	CComboBox m_cmbDB;
	CComboBox m_cmbFC;

	DeviceDefinition m_deviceDef;
};
